package com.study.config;

import com.study.Interceptor.JwtInterceptor;
import com.study.constant.ApiRouterConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author canace
 * @version 1.0
 * @description 接口拦截器
 * @date 2024/1/23 18:25
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final StringRedisTemplate stringRedisTemplate;
    @Autowired
    public WebMvcConfig(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;}

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new JwtInterceptor(stringRedisTemplate));
        registration.addPathPatterns(ApiRouterConstant.BASE_API_ADMIN_V1 + "/**", ApiRouterConstant.BASE_API_V1 + "/**")
                .excludePathPatterns(ApiRouterConstant.BASE_API_ADMIN_USER_V1, ApiRouterConstant.BASE_API_ADMIN_USER_V1 + "/login");
    }
}
